import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/11/18
 * Time: 10:53
 * Description:
 */

public class TestDemo {
    public static int func(int key) {
        int f1 = 0;
        int f2 = 1;
        int f3 = -1;
        while(f3 < key) {
            f3 = f1+f2;
            if(f3 >= key) {
                break;
            }
            f1 = f2;
            f2 = f3;
        }
        if((f3-key) > (key-f2)) {
            return key-f2;
        }else{
            return f3-key;
        }
    }

    public static void main(String[] args){
        Scanner san = new Scanner(System.in);
        while(san.hasNextInt()) {
            int n = san.nextInt();
            int ret = func(n);
            System.out.println(ret);
        }
    }

    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int f1 = 0;
        int f2 = 1;
        int f3 = f1 + f2;
        while (true) {
            if (f2 == n) {
                System.out.println(0);
            } else if (f2 > n) {
                if (Math.abs(f2 - n) > Math.abs(f1 - n)) {
                    System.out.println(Math.abs(f1-n));
                } else {
                    System.out.println(Math.abs(f2-n));
                }
                break;
            }
            f1 = f2;
            f2 = f3;
            f3 = f1 + f2;
        }
    }
}
